import styles from './index.module.scss'

export default function OrderInfo(props) {
  function formatTimestamp(timestamp) {
    const date = new Date(timestamp) // 假设timestamp是秒数，需要乘以1000转换为毫秒
    const year = date.getFullYear()
    const month = String(date.getMonth() + 1).padStart(2, '0') // 月份从0开始，所以需要+1
    const day = String(date.getDate()).padStart(2, '0')
    const hours = String(date.getHours()).padStart(2, '0')
    const minutes = String(date.getMinutes()).padStart(2, '0')
    const seconds = String(date.getSeconds()).padStart(2, '0')
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
  }

  const formattedCreateTime = formatTimestamp(props.createTime) // 格式化时间戳
  return (
    <div className={styles.orderInfo}>
      <ul className={styles.ul}>
        <li className={styles.li}>
          <span className={styles.name}>订单编号：</span>
          <span className={styles.value}>{props.id}</span>
        </li>
        <li className={styles.li}>
          <span className={styles.name}>支付方式：</span>
          <span className={styles.value}>{props.payMethod}</span>
        </li>
        <li className={styles.li}>
          <span className={styles.name}>下单时间：</span>
          <span className={styles.value}>{formattedCreateTime}</span>
        </li>
      </ul>
    </div>
  )
}
